<?
	include 'inc/conn.php';
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);

	if(isset($act)){
		$db = new mysql();
		if($act=="q"){
			echo "[DATA]\r\n";
			$db->query("SELECT * FROM `test_partnum` where IsEnable=1 order by PartNum");
			$num = $db->db_num_rows();
	
			if($num == 0) {echo ":[Error]: No Data";}
	
			for($i=0; $i<$num; $i++){
				$row = $db->fetch_assoc();
				echo "${row['PartNum']}=${row['TestCode']}\r\n";
			}
		}

		if($act=="c" && isset($partnum)){
			$db->query("SELECT * FROM `test_partnum` where PartNum = '${partnum}'");
			$num = $db->db_num_rows();
			if($num > 0) {echo ":[Info]: Part Number already exist\r\n";}else{
				echo ":[Error]: No Data";

				$to = "A-TFS-ENG-EE-TE@hd.tongfangpc.com";
				$title = "【料号添加提醒】: $partnum";

				$Message = "在服务器上没有找到该料号，请及时添加测试的维护料号<br /><br />
							<b>需维护的料号:</b> $partnum<br />";

				//$Message = str_replace("-", "<br />", $Message);

				$headers = "X-Mailer:PHP\n";
				$headers.= "MIME-Version: 1.0\n";
				$headers.= "Content-type:text/html;charset=utf-8\n";
				$headers.= "X-Priority: 1\n";
				$headers.= "From: MON_PN<MON_PN@hd.tongfangpc.com>\r\n"; 
				$message = "<html><head><meta charset='utf-8'></head><body>${Message}</body></html>";
				$subject = "${title}";

				$message=wordwrap($message, 70);

				if (mail($to, $subject, $message, $headers)) {
					echo " - 邮件发送成功!\r\n";
				} else {
					mail($to, $subject, $message, $headers);
				}
			}
		}
		$db->close();
	}
?>